<?php


namespace api\web\controller;

use api\web\model\SpuModel;
use cmf\controller\RestBaseController;

class SpuController extends RestBaseController
{
    public function index()
    {
        $list = SpuModel::select();
        $this->success('商品显示',$list);
    }

    //查看商品详情
    public function getGoodsInfo(){
        $spu_id = input('spu_id/d');
        $spu = SpuModel::where('id',$spu_id)->find();
        unset($spu['info']);
        $spuAttr = json_decode($spu['attr'],true);
        foreach ($spuAttr as $key => $val){
            $spuAttr[$key]['attr_value'] = explode(',',$val['attr_value']);
        }
        $spu['attr'] = $spuAttr;
        $this->success('商品详情',$spu);
    }

}